package com.gitee.wsl.doc.sample.opml.bean

import kotlinx.serialization.Serializable

/**
 * Contains the content of the outline. Must have at least one outline element.
 */
@Serializable
data class Body(
    /**
     * @return unmodifiable [List] holding every [com.gitee.wsl.doc.sample.opml.bean.Outline] in this [Body]
     */
    // A <body> contains one or more <outline> elements
    val outlines: List<com.gitee.wsl.doc.sample.opml.bean.Outline> = emptyList()
)  {

    /**
     * @param index
     * index of the element to return
     * @return [com.gitee.wsl.doc.sample.opml.bean.Outline] at the given index, or `null` if there is no element at that index
     */
    fun getOutline(index: Int): com.gitee.wsl.doc.sample.opml.bean.Outline? {
        if (index < outlines.size) {
            return outlines[index]
        }
        return null
    }

    override fun toString(): String {
        val sb = StringBuilder("Body [outlines=")
        for (outline in outlines) {
            sb.append(System.lineSeparator()).append(outline)
        }
        return sb.append("]").toString()
    }

}